﻿using System.Windows.Input;
using Bookvar.ObjectModel.Actions;
using Bookvar.UI.Commands;

namespace Bookvar.UI.ViewModel
{
    internal partial class MindmapViewModel
    {
        private class DeleteTopicCommand : CommandModel
        {
            private readonly MindmapViewModel viewModel;

            public DeleteTopicCommand( MindmapViewModel viewModel )
                : base( BookvarCommands.DeleteTopic )
            {
                this.viewModel = viewModel;
            }

            protected internal override void OnExecute( object sender, ExecutedRoutedEventArgs e )
            {
                if ( viewModel.SelectedTopic != null )
                {
                    var action = new DeleteTopicAction( viewModel.SelectedTopic, viewModel.Mindmap );

                    ActionService.Execute( action );
                }
            }

            protected internal override void OnCanExecute( object sender, CanExecuteRoutedEventArgs e )
            {
                e.CanExecute = true;
                e.Handled = true;
            }
        }
    }
}